import {
	mapMutations
} from 'vuex'
export default {
	...mapMutations([
		'upUserInfo'
	]),
	bindPickerChange(e) {
		let that = this;
		this.userInfo.gender = e.detail.value + 1;
		that.$httpRequest.request({
			that: that,
			url: 'wechat/editUserInfo',
			params: {
				gender: that.userInfo.gender
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.upUserInfo(that.userInfo)

				}
			}
		})
	},
	bindDateChange(e) {
		console.log(e)
		let that = this;
		this.userInfo.birthdate = e.detail.value;
		that.$httpRequest.request({
			that: that,
			url: 'wechat/editUserInfo',
			params: {
				birthdate: that.userInfo.birthdate
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.upUserInfo(that.userInfo)

				}
			}
		})
	},
	getUserInfo() {
		let that = this
		that.$httpRequest.request({
			that: that,
			url: 'wechat/info',
			method: 'get',
			params: {

			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.upUserInfo(res.data)
					console.log(that.userInfo)
					// setTimeout(function () {
					// 		    uni.hideLoading();
					// 		}, 200);
				} else {
					that.upUserInfo({})
				}
			}
		})
	},
	upAvatarBg() {
		let that = this
		that.$httpRequest.handlerUploadPic(res => {
			if (res.code === that.$httpConfig.SUCCESS_CODE) {
				let backgroundImage = res.data.filePath
				that.$httpRequest.request({
					that: that,
					url: 'wechat/editUserInfo',
					params: {
						backgroundImage: backgroundImage,
					},
					success: res => {
						// that.$toast.alert({
						// 	content: res.message,
						// 	callback: result => {

						// 	}
						// })
						if (res.code === that.$httpConfig.SUCCESS_CODE) {
							that.userInfo.backgroundImage = backgroundImage
							console.log('userInfo', that.userInfo)
							that.upUserInfo(that.userInfo)
						} else {

						}
					}
				})
			}
		})
	},
	upAvatar() {
		let that = this
		that.$httpRequest.handlerUploadPic(res => {
			if (res.code === that.$httpConfig.SUCCESS_CODE) {
				let avatar = res.data.filePath
				that.$httpRequest.request({
					that: that,
					url: 'wechat/editUserInfo',
					params: {
						avatar: avatar,
					},
					success: res => {
						// that.$toast.alert({
						// 	content: res.message,
						// 	callback: result => {

						// 	}
						// })
						if (res.code === that.$httpConfig.SUCCESS_CODE) {
							that.userInfo.avatar = avatar
							that.upUserInfo(that.userInfo)
						} else {

						}
					}
				})
			}
		})
	},
	toEditNickname() {
		let that = this
		if (that.atLoading) {
			//禁止多次点击
			return false
		}
		that.atLoading = true
		uni.navigateTo({
			url: '/pages/my/editNickname'
		})
		setTimeout(() => { //延时指定时间后，再解冻
			that.atLoading = false;
		}, 1000);

	},
	toEditIntro() {
		let that = this
		if (that.atLoading) {
			//禁止多次点击
			return false
		}
		that.atLoading = true
		uni.navigateTo({
			url: '/pages/my/introduction'
		})
		setTimeout(() => { //延时指定时间后，再解冻
			that.atLoading = false;
		}, 1000);

	},
	logout() {
		let that = this
		let url = ''
		// #ifdef MP-WEIXIN || H5
		url = '/pages/publics/reg',
			// #endif
			// #ifdef APP-PLUS
			url = '/pages/publics/reg'
		// #endif
		that.$toast.confirm({
			content: '确定要退出登录吗？',
			callback: result => {
				if (result) {
					// uni.removeStorageSync('token');
					uni.clearStorageSync()
					that.$toast.alert({
						content: '退出登录成功',
						callback: res => {
							if (res.confirm) {
								uni.reLaunch({
									url
								})
							}
						}
					})
				}
			}
		})
	},
	getDate(type) { //年月日
		const date = new Date();
		// const date = new Date();
		let year = date.getFullYear();
		let month = date.getMonth() + 1;
		let day = date.getDate();

		if (type === 'start') {
			year = year - 60;
		} else if (type === 'end') {
			year = year + 2;
		}
		month = month > 9 ? month : '0' + month;
		day = day > 9 ? day : '0' + day;
		return `${year}-${month}-${day}`;
	},
}